﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace LiveEduWizard
{
    public class AgendaViewModel: INotifyPropertyChanged
    {
        public AgendaViewModel()
        {
            Items = new ObservableCollection<AppointmentViewModel>();
        }

        public ObservableCollection<AppointmentViewModel> Items { get; private set; }

        private DateTime date;
        public DateTime Date
        {
            get
            {
                return date;
            }
            set
            {
                if (value != date)
                {
                    date = value;
                    NotifyPropertyChanged("Date");
                }
            }
        }

        private int week;
        public int Week
        {
            get
            {
                return week;
            }
            set
            {
                if (value != week)
                {
                    week = value;
                    NotifyPropertyChanged("Week");
                }
            }
        }

        private int weekYear;
        public int WeekYear
        {
            get
            {
                return weekYear;
            }
            set
            {
                if (value != weekYear)
                {
                    weekYear = value;
                    NotifyPropertyChanged("WeekYear");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        internal bool TryAdd(AppointmentViewModel appointment)
        {
            if (appointment.Start.Date == date)
            {
                Items.Add(appointment);
                return true;
            }
            else
                return false;
        }

        internal static AgendaViewModel Create(AppointmentViewModel firstAppointment)
        {
            var agenda = new AgendaViewModel();
            
            agenda.Date = firstAppointment.Start.Date;
            agenda.WeekYear = firstAppointment.WeekYear;
            agenda.Week = firstAppointment.Week;

            agenda.Items.Add(firstAppointment);

            return agenda;
        }
    }
}
